home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-07 | 3.2 KB | 106 lines |
- /*
- * Java Port Scanner
- *
- * Copyright 2000 Matteo Baccan <mbaccan@planetisa.com>
- * www - http://www.infomedia.it/artic/Baccan
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
- * their web site at http://www.gnu.org/).
- *
- */
-
- import java.net.*;
-
- public class scanSingleIP extends Thread{
- private String cIPToFind;
- private int nPort;
- private String cDesc;
- private boolean bLog;
- private int nTimeout;
- private portScanner parent;
-
- public scanSingleIP( portScanner parent,
- String cIP,
- int nPort,
- String cDesc,
- boolean bLog ,
- int nTimeout ){
- this.parent = parent;
- this.cIPToFind = cIP;
- this.nPort = nPort;
- this.cDesc = cDesc;
- this.bLog = bLog;
- this.nTimeout = nTimeout;
- }
-
- public void run(){
- while( true ){
- try {
- long nMils = System.currentTimeMillis();
-
- if( bLog )
- log( cIPToFind +"(" +nPort +")" );
-
- Socket test = new Socket( cIPToFind, nPort );
- nMils = System.currentTimeMillis()-nMils;
-
- String cReply = "";
- try {
- test.setSoTimeout( nTimeout );
- int nChar = 0;
- while( (nChar=test.getInputStream().read())>-1 )
- cReply += (char)nChar;
- }catch( Throwable e ){
- //log( e.toString() );
- //e.printStackTrace();
- }
-
- test.close();
-
- String cString2Ret = "Found : " +cIPToFind +" " +cDesc;
- cString2Ret += "(" +new Integer(nPort).toString() +")";
- cString2Ret += " Millis(" +new Long(nMils).toString() +")\n";
- if( cReply.length()>0 ){
- cString2Ret += "Reply\n";
- cString2Ret += cReply;
- }else{
- cString2Ret += "NoReply\n";
- }
-
- log( cString2Ret );
- break;
- }catch(ConnectException e){
- break;
- }catch(SocketException e){
- log( "Too many threads. Decrease the number of Thread" );
- break;
- }catch(Throwable e){
- //log( e.toString() );
- //e.printStackTrace();
- break;
- }
- }
- parent.threadDel();
- stop();
- }
-
- public void log( int nMsg ){
- log( new Integer( nMsg ).toString() );
- }
- public void log( String cMsg ){
- parent.log( cMsg );
- }
- }
-